home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstdio.arc / SRC.ARC / CML.A < prev    next >
Text File  |  1985-08-28  |  1KB  |  85 lines

  1. ;    cml.a - convert memory line.
  2. ;    (C) Copyright 1985 Cray Research Inc. - All Rights Reserved.
  3. ;    G. R. Mansfield.  85/06/18.
  4. ;    Ver 1.0-5828.
  5.  
  6.  
  7.     cseg
  8.     public    cml_
  9.  
  10.  
  11. ;    cml(s, a, d)    /* convert memory line */
  12. ;    BYTE *a, *d;
  13. ;    char *s;
  14.  
  15. cml_:    mov    bx,sp
  16.     mov    di,[bx+2]    ; destination string
  17.     mov    si,[bx+4]    ; memory address
  18.     mov    ax,[bx+6]    ; convert address
  19.     call    chw
  20.  
  21. ;    convert hexadecimal data.
  22.  
  23.     mov    cx,16
  24. cml1:    mov    al,' '        ; space to separate bytes
  25.     stosb
  26.     test    cl,3        ; check conversion
  27.     jnz    cml2        ; if not 4 bytes
  28.     stosb            ; add space
  29. cml2:    lodsb            ; convert byte
  30.     call    chb
  31.     loop    cml1        ; loop for 16 bytes
  32.  
  33. ;    add ASCII characters.
  34.  
  35.     mov    al,' '        ; space to separate fields
  36.     stosb
  37.     stosb
  38.     mov    cx,16
  39.     sub    si,cx
  40. cml3:    lodsb            ; next byte
  41.     cmp    al,020h        ; change non-displayable to '.'
  42.     jb    cml4
  43.     cmp    al,07Fh
  44.     jbe    cml5
  45. cml4:    mov    al,'.'
  46. cml5:    stosb
  47.     loop    cml3        ; loop for 16 bytes
  48.  
  49.     mov    al,0        ; end line
  50.     stosb
  51.     ret
  52.  
  53.  
  54. ;    chw - Convert hexadecimal word.
  55. ;    entry    ax = word.
  56.  
  57. chw:    push    ax        ; upper byte
  58.     xchg    al,ah
  59.     call    chb
  60.     pop    ax        ; lower byte
  61. ;    jmp    chb
  62.  
  63.  
  64. ;    chb - Convert hexadecimal byte.
  65. ;    entry    al = byte.
  66.  
  67. chb:    push    ax        ; upper digit
  68.     shr    al,1
  69.     shr    al,1
  70.     shr    al,1
  71.     shr    al,1
  72.     add    al,090h        ; 10 - 15 to 'A' - 'F'
  73.     daa
  74.     adc    al,040h        ; 0 - 9 to '0' - '9'
  75.     daa
  76.     stosb
  77.     pop    ax        ; lower digit
  78.     and    al,00Fh
  79.     add    al,090h        ; 10 - 15 to 'A' - 'F'
  80.     daa
  81.     adc    al,040h        ; 0 - 9 to '0' - '9'
  82.     daa
  83.     stosb
  84.     ret
  85.